﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wei8808Cms.BLL;
using Wei8808Cms.Model;
using Wei8808Cms.WebSite.UI;

namespace Wei8808Cms.WebSite.admin.News
{
    public partial class AddNewsInfoForm : BasicPage
    {
        private readonly NewsBLL _bll = new NewsBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindDropdowLists();
                chkLoginLevel("addNews");
            }
        }

        protected void BindDropdowLists()
        {
            var list = new NewTypeBLL().GetNewTypeList();
            ddlNewType.DataSource = list;
            ddlNewType.DataValueField = "NewTypeId";
            ddlNewType.DataTextField = "NewTypeName";
            ddlNewType.DataBind();
            ddlNewType.Items.Insert(0, new ListItem("--所有类别--", ""));
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            var model = new NewsInfo();
            model.NewTitle = txtNewTitle.Text.Trim();
            model.Author = txtAuthor.Text.Trim();
            model.Source = txtSource.Text.Trim();
            model.MetaKeywords = txtMetaKeywords.Text.Trim();
            model.MetaDescription = txtMetaDescription.Text.Trim();
            model.NewTypeId = Convert.ToInt32(ddlNewType.SelectedValue);
            model.NewContent = FCKeditor.Value;
            model.Click = int.Parse(txtClick.Text.Trim());
            model.IsTop = 0;
            model.IsRec = 0;
            if (cblItem.Items[0].Selected == true)
            {
                model.IsTop = 1;
            }
            if (cblItem.Items[1].Selected == true)
            {
                model.IsRec = 1;
            }
            model.CreateUser = "李波";
            model.CreateTime = DateTime.Now;
            if (_bll.Add(model))
            {
                JscriptPrint("保存成功！", "AddNewsInfoForm.aspx", "Success");
            }
            else
            {
                JscriptPrint("保存失败！", "", "Error");
            }
        }
    }
}